package com.nku.mason.scm.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nku.mason.scm.service.AccountRecordsService;
import com.nku.mason.scm.service.SupplierService;
import com.nku.mason.scm.vo.PageBean;
import com.nku.mason.scm.vo.Supplier;

@Controller
@RequestMapping("/supplier")
public class SupplierAction {
	
	@Resource
	private SupplierService supplierService;
	
	@Resource
	private AccountRecordsService accountRecordsService;
	
	@RequestMapping("/selectPage")
	@ResponseBody
	public Object selectPage(PageBean<Supplier> page , Supplier supplier){
		System.out.println("-----selectPage.page" + page);
		System.out.println("-----selectPage.supplier" + supplier);
		page.setParamEntity(supplier);
		try {
			page = supplierService.selectPage(page);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page.getPageMap();
	}
	
	@RequestMapping("/deleteByPks")
	@ResponseBody
	public Object deleteByPks(String [] pks) {
		System.out.println("---deleteByPks.pks:" + pks);
		int i = 0;
		try {
			i = supplierService.deleteByPks(pks);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	@RequestMapping("/insert")
	@ResponseBody
	public Object insertSupplier(Supplier supplier){
		System.out.println("---insertSupplier:" + supplier);
		int i = 0;
		try {
			i = supplierService.insert(supplier);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public Object updateSupplier(Supplier supplier){
		System.out.println("---updateSupplier:" + supplier);
		int i = 0;
		try {
			i = supplierService.update(supplier);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return i;
	}
	
	@RequestMapping("/selectSupplier")
	@ResponseBody
	public Object selectSupplier(String start,String end){
		System.out.println("start:"+ start+"||end:"+end);
		Map<String, String> paramMap =new HashMap<String, String>();
		paramMap.put("start", start);
		paramMap.put("end", end);

		return accountRecordsService.selectSupplier(paramMap);
	}
}








































